package com.edu.exam.entity.quality.monitoring;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;

/**
 * 分配配置实体类
 *
 * 根据E-06-01任务分配子模块设计实现
 * 对应allocation_config数据表，用于存储系统级的分配配置参数
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
public class AllocationConfig {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "config_key", length = 100, unique = true, nullable = false)
    private String configKey;

    @Column(name = "config_value", columnDefinition = "TEXT", nullable = false)
    private String configValue;

    @Column(name = "config_type", length = 20, nullable = false)
    private String configType; // TODO: 迁移到外部枚举 AllocationConfigType

    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    @Column(name = "is_system", nullable = false)
    private Boolean isSystem;

    @Column(name = "enabled", nullable = false)
    private Boolean enabled;

    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @Column(name = "update_time", nullable = false)
    private LocalDateTime updatedTime;

    @Column(name = "updated_by", length = 50)
    private String updatedBy;

    // 扩展字段
    @Column(name = "category", length = 50)
    private String category; // 配置分类

    @Column(name = "sub_category", length = 50)
    private String subCategory; // 子分类

    @Column(name = "data_type", length = 20)
    private String dataType; // 数据类型

    @Column(name = "default_value", columnDefinition = "TEXT")
    private String defaultValue; // 默认值

    @Column(name = "validation_pattern", length = 500)
    private String validationPattern; // 验证正则表达式

    @Column(name = "min_value")
    private Double minValue; // 最小值（数值类型）

    @Column(name = "max_value")
    private Double maxValue; // 最大值（数值类型）

    @Column(name = "allowed_values", columnDefinition = "TEXT")
    private String allowedValues; // 允许的值列表（JSON数组）

    @Column(name = "unit", length = 20)
    private String unit; // 单位

    @Column(name = "priority")
    private Integer priority; // 优先级

    @Column(name = "sensitivity", length = 20)
    private String sensitivity; // 敏感级别

    @Column(name = "access_level", length = 20)
    private String accessLevel; // 访问级别

    @Column(name = "requires_restart")
    private Boolean requiresRestart; // 是否需要重启生效

    @Column(name = "encrypted")
    private Boolean encrypted; // 是否加密存储

    @Column(name = "read_only")
    private Boolean readOnly; // 是否只读

    @Column(name = "publicly_accessible")
    private Boolean publiclyAccessible; // 是否公开访问

    @Column(name = "cacheable")
    private Boolean cacheable; // 是否可缓存

    @Column(name = "cache_ttl_seconds")
    private Integer cacheTtlSeconds; // 缓存生存时间（秒）

    @Column(name = "last_accessed_time")
    private LocalDateTime lastAccessedTime; // 最后访问时间

    @Column(name = "access_count")
    private Long accessCount; // 访问次数

    @Column(name = "modification_history", columnDefinition = "TEXT")
    private String modificationHistory; // 修改历史（JSON数组）

    @Column(name = "change_reason", columnDefinition = "TEXT")
    private String changeReason; // 修改原因

    @Column(name = "approval_required")
    private Boolean approvalRequired; // 是否需要审批

    @Column(name = "approved_by", length = 50)
    private String approvedBy; // 审批人

    @Column(name = "approval_time")
    private LocalDateTime approvalTime; // 审批时间

    @Column(name = "approval_comments", columnDefinition = "TEXT")
    private String approvalComments; // 审批意见

    @Column(name = "environment", length = 20)
    private String environment; // 环境标识

    @Column(name = "version")
    private Integer version; // 版本号

    @Column(name = "deprecated")
    private Boolean deprecated; // 是否已弃用

    @Column(name = "deprecation_date")
    private LocalDateTime deprecationDate; // 弃用日期

    @Column(name = "deprecation_message", columnDefinition = "TEXT")
    private String deprecationMessage; // 弃用消息

    @Column(name = "sunset_date")
    private LocalDateTime sunsetDate; // 停用日期

    @Column(name = "tags", length = 500)
    private String tags; // 标签（逗号分隔）

    @Column(name = "notes", columnDefinition = "TEXT")
    private String notes; // 备注


    }
